package com.bsoft.exchange.controller.hospitalization;

import java.util.List;

import com.bsoft.exchange.domain.HealthRecordsDomain;
import com.bsoft.exchange.pojo.HealthRecordsPojo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bsoft.exchange.domain.AdmissionNoteDomain;
import com.bsoft.exchange.domain.DrugFrequencyDomain;
import com.bsoft.exchange.domain.SyncTemplateDomain;
import com.bsoft.exchange.pojo.CostAggregationPojo;
import com.bsoft.exchange.pojo.MedicalRecordIdPojo;
import com.bsoft.exchange.pojo.OrganizationIdPojo;
import com.bsoft.exchange.response.ResponseEntity;
import com.bsoft.exchange.service.RecordService;
import com.bsoft.exchange.util.BaseResponse;
import com.bsoft.exchange.util.Constant;

import io.swagger.annotations.ApiOperation;

import javax.servlet.http.HttpServletRequest;

/**
 * 病历相关接口
 */

@RestController
@RequestMapping(value = "healthRecords")
public class HealthRecordController {
	@Autowired
	private RecordService recordService;
	
	@ApiOperation(value = "同步病历类别信息")
	@RequestMapping(value = "/syncTemplate",method = RequestMethod.POST,produces = "application/json")
	public ResponseEntity<List<SyncTemplateDomain>> syncTemplate(@RequestBody OrganizationIdPojo  organizationIdPojo)  {
		ResponseEntity<List<SyncTemplateDomain>> entity=new ResponseEntity();
		try{
		BaseResponse<List<SyncTemplateDomain>> returnMessage = recordService.syncTemplate(organizationIdPojo);
	
		entity.setCode(returnMessage.getCode());
    	entity.setMessage(returnMessage.getMessage());
		entity.setData(returnMessage.getData());
		
		}catch(Exception e){
			entity.setCode(Constant.errorTag);
			entity.setMessage(e.getMessage()); 
		}

		return entity;

	}
	
	@ApiOperation(value = "获取住院病历信息")
	@RequestMapping(value = "/admissionNote",method = RequestMethod.POST,produces = "application/json")
	public ResponseEntity<List<AdmissionNoteDomain>> admissionNote(@RequestBody CostAggregationPojo  costAggregationPojo,
																   HttpServletRequest request)  {
		ResponseEntity<List<AdmissionNoteDomain>> entity=new ResponseEntity();
		try{
		BaseResponse<List<AdmissionNoteDomain>> returnMessage = recordService.admissionNote(costAggregationPojo,request);
	
		entity.setCode(returnMessage.getCode());
    	entity.setMessage(returnMessage.getMessage());
		entity.setData(returnMessage.getData());
		
		}catch(Exception e){
			entity.setCode(Constant.errorTag);
			entity.setMessage(e.getMessage()); 
		}

		return entity;

	}
	
	@ApiOperation(value = "获取病历html")
	@RequestMapping(value = "/getRecordUrl",method = RequestMethod.POST,produces = "application/json")
	public ResponseEntity<String> getRecordUrl(@RequestBody MedicalRecordIdPojo medicalRecordIdPojo)  {
		ResponseEntity<String> entity=new ResponseEntity();
		try{
			BaseResponse<String> returnMessage = recordService.getRecordUrl(medicalRecordIdPojo);
		
			entity.setCode(returnMessage.getCode());
	    	entity.setMessage(returnMessage.getMessage());
			entity.setData(returnMessage.getData());
		
		}catch(Exception e){
			entity.setCode(Constant.errorTag);
			entity.setMessage(e.getMessage()); 
		}

		return entity;

	}
	@ApiOperation(value = "获取健康记录列表")
	@RequestMapping(value = "/healthRecordsList",method = RequestMethod.POST,produces = "application/json")
	public ResponseEntity healthRecordsList(@RequestBody @Validated HealthRecordsPojo healthRecordsPojo){
		ResponseEntity responseEntity=new ResponseEntity();
		BaseResponse<List<HealthRecordsDomain>> baseResponse=recordService.getHealthRecordsList(healthRecordsPojo);
		responseEntity.setCode(baseResponse.getCode());
		responseEntity.setMessage(baseResponse.getMessage());
		responseEntity.setData(baseResponse.getData());
		return responseEntity;
	}
}
